$(document).ready(function() {
				$(".error").hide();
				$(".tab_content").hide(); //Hide all content
				$("ul.tabs li:first").addClass("active").show(); //Activate first tab
				$(".tab_content:first").show(); //Show first tab content
				
				//On Click Event
				$("ul.tabs li").click(function() {
				
				$("ul.tabs li").removeClass("active"); //Remove any "active" class
				$(this).addClass("active"); //Add "active" class to selected tab
				$(".tab_content").hide(); //Hide all tab content
				var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
				$(activeTab).fadeIn(); //Fade in the active ID content
				return false;
				});
				
				$("#add_book").click(function(){
					var t_title = $("#ab_title").val();
					var t_author = $("#ab_author").val();
					var t_subject = $("#ab_subject").val();
					
					if(t_title == '' || t_author == '' || t_subject == '')
					{
						$("#ab_error").slideDown();
					}
					else
					{
						$.post("../Book/AddBook",{
						    "title": t_title,
						    "author": t_author,
						    "subject": t_subject
						},function(data){
						    $(".error").slideUp();
						    $("#ab_success").slideDown(800).delay(800).slideUp();
						    $("#ab_title").val("");
						    $("#ab_author").val("");
						    $("#ab_subject").val("");
						});
						
					}
				
				});
				
				$("#sb_button").click(function(){
					var search = $("#sb_book").val();
					
					if(search == '')
					{
						$("#sb_error").slideDown();
					}
					else
					{
						alert("Book Searched!");
					}
				
				});
				
				$("#s_button").click(function(){
					var search = $("#s_book").val();
					
					if(search == '')
					{
						$("#s_error").slideDown();
					}
					else
					{
						alert("Book Searched!");
					}
				
				});
				
				$("#su_button").click(function(){
					var search = $("#su_user").val();
					
					if(search == '')
					{
						$("#su_error").slideDown();
					}
					else
					{
						alert("User Searched!");
					}
				
				});
				
				$("#au_button").click(function(){
					var username = $("#au_username").val();
					var pass = $("#au_pass").val();
					var confirm = $("#au_confirm").val();
					var fname = $("#au_fname").val();
					var lname = $("#au_lname").val();
					var email = $("#au_email").val();
					var level = $("#au_level").val();
					
					if(username == '' || pass == '' || confirm == '' || fname == '' || lname == '' || email == '')
					{
						$("#au_error").slideDown();
					}
					else if(pass != confirm)
					{
						$("#au_error_pass").slideDown();
					}
					else
					{
						$.post("../User/AddUser",{
						    "username": username,
						    "pass": pass,
						    "fname": fname,
						    "lname": lname,
						    "email": email,
						    "level" : level
						},function(data){
						    $(".error").slideUp();
						    $("#au_success").slideDown(800).delay(800).slideUp();
						    
						    $("#au_username").val("");
							$("#au_pass").val("");
							$("#au_confirm").val("");
							$("#au_fname").val("");
							$("#au_lname").val("");
							$("#au_email").val("");
							$("#au_level").val("");
						});
						
						alert("User added");
					}
				
				});
				
				$(".deleteBook").click(function(){
					var id = $(this).attr("id");					
					var row = "#"+id+"_row";			
					
					$.post("../Book/deleteBook",{
						    "book_id": id
						},function(data){
							$("#db_success").slideDown(800).delay(800).slideUp();
						    $(".error").slideUp();
						    $(row).fadeOut();
						});
				});
				
				$(".editBook_showForm").click(function(){
					$("#form_editBook").slideDown();
					var id = $(this).attr("id");   
					$("#inp_id").val(id);
					$("#inp_title").val( $("#"+id+"_title").html() );
					$("#inp_author").val( $("#"+id+"_author").html() );
					$("#inp_subject").val( $("#"+id+"_subject").html() );
					
					return false;
				});
				
				$("#cancel_editBook").click(function(){
					$("#form_editBook").slideUp();
				});
				
				$("#editBook").click(function(){
					var id = $("#inp_id").val();
					var title = $("#inp_title").val();
					var author = $("#inp_author").val();
					var subject = $("#inp_subject").val();					
					
					if(id != "" || title != "" || author != "" || subject != "")
					{
						$.post("../Book/editBook",{
						    "book_id": id,
						    "title": title,
						    "author": author,
						    "subject": subject
						},function(data){
							$("#eb_success").slideDown(800).delay(800).slideUp();
							$("#form_editBook").slideUp();
						    $(".error").slideUp();	
						    $("#"+id+"_title").html( title );
						    $("#"+id+"_author").html( author );
						    $("#"+id+"_subject").html( subject );				    
						});
					}
					
				
				});
				
			});
			